﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Oscilloscope.Util;

namespace Oscilloscope.Screen
{
	// Token: 0x0200001E RID: 30
	internal class CurveMoveMouseTool : MouseTool
	{
		// Token: 0x06000116 RID: 278 RVA: 0x0000906C File Offset: 0x0000726C
		public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e, OscilloscopeScreen oscilloscope)
		{
			base.OnMouseDown(drawArea, e, oscilloscope);
			if (this.functionMode != CurveMoveMouseTool.FunctionMode.ShowData)
			{
				return;
			}
			if (e.Button == MouseButtons.Left)
			{
				this.functionMode = CurveMoveMouseTool.FunctionMode.Move;
				this.lastPoint.X = e.X;
				this.lastPoint.Y = e.Y;
				oscilloscope.Cursor = Cursors.SizeAll;
			}
			else if (e.Button == MouseButtons.Right)
			{
				this.functionMode = CurveMoveMouseTool.FunctionMode.Ranging;
				this.lastPoint.X = e.X;
				this.lastPoint.Y = e.Y;
				this.startPoint.X = e.X;
				this.startPoint.Y = e.Y;
			}
			if (this.functionMode == CurveMoveMouseTool.FunctionMode.Ranging)
			{
				ControlPaint.DrawReversibleFrame(drawArea.RectangleToScreen(InternalUtils.GetNormalizedRectangle(this.startPoint, this.lastPoint)), Color.White, FrameStyle.Dashed);
				oscilloscope.RangingStart();
			}
		}

		// Token: 0x06000117 RID: 279 RVA: 0x00009158 File Offset: 0x00007358
		public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e, OscilloscopeScreen oscilloscope)
		{
			base.OnMouseMove(drawArea, e, oscilloscope);
			Point p = this.lastPoint;
			if (this.functionMode == CurveMoveMouseTool.FunctionMode.Move) //移动channel
			{
				int num = e.X - this.lastPoint.X;
				int num2 = e.Y - this.lastPoint.Y;

				if (Math.Abs(num) >= this.landscapeMoveSensitivity && num != 0)
				{
					if (num > 0)
					{
						oscilloscope.MoveWindowLeft(Math.Abs(num) / this.landscapeMoveSensitivity);
					}
					else if (num < 0)
					{
						oscilloscope.MoveWindowRight(Math.Abs(num) / this.landscapeMoveSensitivity);
					}
					this.lastPoint.X = e.X;
				}
				if (Math.Abs(num2) >= this.portraitMoveSensitivity && num2 != 0)
				{
					if (num2 > 0)
					{
						oscilloscope.MoveSelectedChannelWaveDown(Math.Abs(num2) / this.portraitMoveSensitivity);
					}
					else if (num2 < 0)
					{
						oscilloscope.MoveSelectedChannelWaveUp(Math.Abs(num2) / this.portraitMoveSensitivity); //触发曲线
					}
					this.lastPoint.Y = e.Y;
					return;
				}
			}
			else
			{
				if (this.functionMode == CurveMoveMouseTool.FunctionMode.Ranging)
				{
					int mOffset = Math.Abs(e.X - this.startPoint.X);
					int vOffset = Math.Abs(e.Y - this.startPoint.Y);
					this.lastPoint.X = e.X;
					this.lastPoint.Y = e.Y;
					ControlPaint.DrawReversibleFrame(drawArea.RectangleToScreen(InternalUtils.GetNormalizedRectangle(this.startPoint, p)), Color.White, FrameStyle.Dashed);
					ControlPaint.DrawReversibleFrame(drawArea.RectangleToScreen(InternalUtils.GetNormalizedRectangle(this.startPoint, this.lastPoint)), Color.White, FrameStyle.Dashed);
					oscilloscope.Ranging(mOffset, vOffset);
					return;
				}
				if (this.functionMode == CurveMoveMouseTool.FunctionMode.ShowData)
				{
					oscilloscope.ShowCurvePointValue(new Point(e.X, e.Y));
					oscilloscope.ShowCurvePointValues(new Point(e.X, e.Y));
                }
			}
		}

		// Token: 0x06000118 RID: 280 RVA: 0x0000931C File Offset: 0x0000751C
		public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e, OscilloscopeScreen oscilloscope)
		{
			base.OnMouseUp(drawArea, e, oscilloscope);
			if (this.functionMode == CurveMoveMouseTool.FunctionMode.Move)
			{
				oscilloscope.Cursor = Cursors.Default;
			}
			else if (this.functionMode == CurveMoveMouseTool.FunctionMode.Ranging)
			{
				ControlPaint.DrawReversibleFrame(drawArea.RectangleToScreen(InternalUtils.GetNormalizedRectangle(this.startPoint, this.lastPoint)), Color.White, FrameStyle.Dashed);
				oscilloscope.RangingStop();
			}
			this.functionMode = CurveMoveMouseTool.FunctionMode.ShowData;
		}

		// Token: 0x0400007C RID: 124
		private CurveMoveMouseTool.FunctionMode functionMode = CurveMoveMouseTool.FunctionMode.ShowData;

		// Token: 0x0400007D RID: 125
		private Point lastPoint = new Point(0, 0);

		// Token: 0x0400007E RID: 126
		private Point startPoint = new Point(0, 0);

		// Token: 0x0400007F RID: 127
		private int landscapeMoveSensitivity = 2;

		// Token: 0x04000080 RID: 128
		private int portraitMoveSensitivity = 2;

		// Token: 0x0200001F RID: 31
		private enum FunctionMode
		{
			// Token: 0x04000082 RID: 130
			Move,
			// Token: 0x04000083 RID: 131
			Ranging,
			// Token: 0x04000084 RID: 132
			ShowData
		}
	}
}
